import React, { Component } from 'react'
import './style.scss'
import { string, node, oneOfType, func } from 'prop-types'

class NavTab extends Component {
  render() {
    const { title, leftText, rightText, onLeftClick, onRightClick } = this.props
    return (
      <div className='nav-tab'>
        <div className='left' onClick={onLeftClick}>
          {leftText}
        </div>
        <div className='middle'>{title}</div>
        <div className='right' onClick={onRightClick}>
          {rightText}
        </div>
      </div>
    )
  }
}

// 为组件添加属性校验
NavTab.propTypes = {
  title: oneOfType([node, string]).isRequired,
  leftText: oneOfType([node, string]),
  onLeftClick: func,
  rightText: oneOfType([node, string]),
  onRightClick: func
}

// 为组件添加默认属性
NavTab.defaultProps = {
  leftText: '',
  onLeftClick: () => {},
  rightText: '',
  onRightClick: () => {}
}

export default NavTab
